﻿var grid,diffGrid, cbProgress;

//初始化表格
function InitGrid() {
    
    var startDate = $('#StartDate').datebox('getValue');
    var endDate = $('#EndDate').datebox('getValue');
    var tableName = $('#drpTable').combobox('getValue');
    if (startDate == "")
         return;
    if (endDate == "")
        return;
    //if (GetDateRegion(startDate, endDate) > 7)
    //{
    //    $.messager.alert("提示信息","查询时间不能大于7天！", "warning");
    //    return;
    //}
    grid = $('#tab_list').datagrid({
        name: 'tbl_data',
        url: '/OrderCheck/Query',
        title: '订单差异汇总',
        queryParams: {
            startDate: startDate,
            endDate: endDate,
            tableName: tableName
        },
        height: 700,
        fitColumns: false,
        rownumbers: true,
        singleSelect: true,
        idField: 'ID',
        columns: [[
                    { field: 'ID', title: '序号', hidden: true, width: 100 },
                    { field: 'OrderMissCount', title: '漏单数', align: 'center', sortable: true, width: 200, formatter: RedirecOrderMissCount },
                    { field: 'OrderStutsDiffCount', title: '状态差异数', align: 'center', sortable: true, width: 200, formatter: RedirecOrderStutsDiffCount },
                    { field: 'OrderDistributionCount', title: '配送时间差异数', align: 'center', sortable: true, width: 200, formatter: RedirecOrderDistributionCount },
                     //{ field: 'OrderDetailCount', title: '订单明细差异数', align: 'center', sortable: true, width: 200 }

        ]],
        toolbar: "",
        pagination: true,
        pageSize: 20,
        pageNumber: 1,
        pageList: [10, 20, 30, 40, 50],
        rownumbers: true, //行号
       
      
        onUnselect: function (rowIndex, rowData) {
            onRefreshButton();
        },
        onSortColumn: function (sort, order) {
            grid.datagrid('reload');
        }
    });
};

function RedirecOrderMissCount(v) {
    return '<a href="#"  onclick="DiffInitGrid(1)">  ' + v + '</a>';
}
function RedirecOrderStutsDiffCount(v, d) {
    return '<a href="#"  onclick="DiffInitGrid(2)">  ' + v + '</a>';
}
function RedirecOrderDistributionCount(v, d) {
    return '<a href="#"  onclick="DiffInitGrid(3)">  ' + v + '</a>';
}
function DiffInitGrid(type) {
    $('#p1').dialog('open').dialog('setTitle', '差异订单详情');
   
    diffGrid = $('#diff_list').datagrid({
        name: 'tbl_data',
        url: '/OrderCheck/QueryDiffOrders?type=' + type,
        title: '订单列表',
        
        height: 400,
        fitColumns: false,
        rownumbers: true,
        singleSelect: true,
        idField: 'ID',
        columns: [[
                    { field: 'ID', title: '序号', hidden: true, width: 100 },
                     { field: 'ORDER_SN', title: '订单号', align: 'center', sortable: true, width: 200 },
                    //{ field: 'ORDER_SN', title: '商品名称', align: 'center', sortable: true, width: 200 },
                    { field: 'ORDER_STATUS', title: '状态', align: 'center', sortable: true, width: 200, formatter: GetStatusFormat },
                     { field: 'BEST_TIME', title: '配送时间', align: 'center', sortable: true, width: 200 }
        ]],
        toolbar: "",
        pagination: true,
        pageSize: 20,
        pageNumber: 1,
        pageList: [10, 20, 30, 40, 50],
        rownumbers: true, //行号
       
        onUnselect: function (rowIndex, rowData) {
            onRefreshButton();
        },
        onSortColumn: function (sort, order) {
            diffGrid.datagrid('reload');
        }
    });
};

          
function GetDateRegion(BeginDate,EndDate)
{
                
    var aDate, oDate1, oDate2, iDays;
    //var sDate1=document.getElementById(BeginDate).value;   //sDate1和sDate2是2008-12-13格式
    //var sDate2=document.getElementById(EndDate).value;              
    aDate = EndDate.split("-");
    oDate1 = new Date(aDate[1] + '/' + aDate[2] + '/' + aDate[0]);   //转换为12/13/2008格式
    aDate = BeginDate.split("-");
    oDate2 = new Date(aDate[1] + '/' + aDate[2] + '/' + aDate[0]);
    //iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24)+1;   //把相差的毫秒数转换为天数
    var i=(oDate1 - oDate2) / 1000 / 60 / 60 /24;
    if(i<0)
    {
        i-=1;
    }
    else
    {
        i+=1;
    }
    iDays = i;   //把相差的毫秒数转换为天数
    //alert(iDays);
    return iDays;
}
function GetStatusFormat(val) {
    switch (val)
    {
        case "0":
            return "已确认";
        case "1":
            return "已确认";
        case "2":
            return "已取消";
        case "3":
            return "无效";
        case "4":
            return "退货";
        case "5":
            return "已分单";
        case "6":
            return "部分分单";
        case "7":
            return "退货入库";
        case "8":
            return "退款";
        case "99":
            return val;
    }
}
function Verification() {
    var startDate = $('#StartDate').datebox('getValue');
    var endDate = $('#EndDate').datebox('getValue');
    var tableName = $('#drpTable').combobox('getValue');
    if (startDate == "") {
        $.messager.alert("提示信息", "开始时间不能为空！", "warning");
        return;
    }
    if (endDate == "") {
        $.messager.alert("提示信息", "结束时间不能为空！", "warning");
        return;
    }
}

function ShowTips(orderId,val){
    var result;
    $.post( '/OrderCheck/QueryDiffOrders?orderid='+ orderId, function (data) {    
        if (data!=null)       
            result= data;
    });
    return result;
}
 